<template>
  <section class="jumbotron">
    <h3 class="jumbotron-heading">Search Github Users</h3>
    <div>
      <input
        type="text"
        placeholder="enter the name you search"
        v-model="searchInfo"
      />&nbsp;<button @click="searchHandle">Search</button>
    </div>
  </section>
</template>

<script>
import axios from "axios";
export default {
  name: "Header",
  props: ["getSearchData"],
  data() {
    return {
      searchInfo: "",
    };
  },
  methods: {
    // 搜索 发送ajax请求
    async searchHandle() {
      // 搜索状态
      this.getSearchData({ userInit: false, userSearch: true });
      const result = await axios.get(
        `https://api.github.com/search/users?q=${this.searchInfo}`
      );
      console.log(result);

      // 发送请求成功
      this.getSearchData({ userSearch: false, userList: result.data.items });
    },
  },
};
</script>

<style>
</style>